package com.yanqu.road.server.logic.activity.condition.union;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.task.args.union.UnionActivityBaseArgs;
import com.yanqu.road.entity.task.args.union.UnionRechargeUserArgs;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseUnionActivityCondition;
import com.yanqu.road.utils.string.StringUtils;

import java.math.BigInteger;

/**
 * 商会充值人数
 */
public class UnionRechargeUserCondition extends BaseUnionActivityCondition {

	public UnionRechargeUserCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
		super(activityInfo, activityConditionInfo, baseActivityData);
	}

	@Override
	public void addTrigger(GamePlayer player) {
		player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.UnionRechargeUser.getValue(), handle);
	}

	@Override
	//这个不用移除了，要一直监听
	public void removeTrigger(GamePlayer player) {
//		player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.UnionRechargeUser.getValue(), handle);
	}

    @Override
    public void initDefaultValue() {
		if(isGetReward()){
			return;
		}
		String unionUid = player.getUserInfo().getUnionUid();
		if(StringUtils.isNullOrEmpty(unionUid)){
			setValue(BigInteger.valueOf(0));
			return;
		}
		UnionRechargeUserArgs args = new UnionRechargeUserArgs(UnionActivityBaseArgs.VALUE_IN,0,unionUid,player.getUserId());
		args.setConditionId(getConditionId());
		setUnionActivityDefaultValue(args);
    }

    @Override
	//触发有两种状态，一种是进来设置值，设置完直接返回，一种是进来通知Union这个人充值了然后统计最后再触发一次给所有人，这个时候就是直接设置值
	protected void player_BoardLevelHandle(Object object) {
		UnionRechargeUserArgs args = (UnionRechargeUserArgs) object;
		BigInteger value = args.getSetValue();
		//假如有设置值直接赋值不用通知Mgr了
		if(value.compareTo(BigInteger.valueOf(-1)) != 0){
			setValue(value);
			return;
		}
		if(null != args) {
			args.setConditionId(getConditionId());
			setUnionActivityValue(getValue().add(BigInteger.valueOf(args.getAddValue())),args);
		}
	}
}
